package rolesystem.middle.utilityclasses;

import java.util.ArrayList;

import rolesystem.middle.managers.DataOutputManager;


public class AgentMap
{
	private static ArrayList<AgentData> agentList;
	
	
	static
	{
		agentList= new ArrayList<AgentData>();	
	}
	
	public synchronized static void createAgentMap(int numberOfAgents)
	{
		AgentMap.agentList.clear();
		for(int agent_id=0;agent_id<numberOfAgents;agent_id++)
		{
			AgentMap.agentList.add(agent_id, new AgentData(agent_id));
		}
	}
	
	public synchronized static void setAgent(int agent_id, AgentData updatedAgent) 
	{
			try 
			{
				agentList.set(agent_id,updatedAgent);
			} catch (IndexOutOfBoundsException  e) 
			{
				//this.agentData.add(agent_id, data);
				DataOutputManager.printString("ERROR ERROR ERROR");
			}
	}
	
	public synchronized static void setAgentPosition(int agent_id, PositionSq newPosition) 
	{
			try 
			{
				agentList.get(agent_id).position_agent=new PositionSq(newPosition);
			} catch (IndexOutOfBoundsException  e) 
			{
				//this.agentData.add(agent_id, data);
				DataOutputManager.printString("ERROR ERROR ERROR");
			}
	}
	
	
	public synchronized static void setAgentRoleID(int agent_id,int role_id) 
	{		
		try 
		{
			agentList.get(agent_id).role_id=role_id;
		} catch (IndexOutOfBoundsException  e) 
		{
			//this.agentData.add(agent_id, data);
			DataOutputManager.printString("ERROR ERROR ERROR");
		}
	}
	
	public static int getSize() 
	{
		return agentList.size();	
	}
	
	public static PositionSq getPositionByIndex(int index) 
	{
		return agentList.get(index).position_agent;	
	}
	
	public static int getIdByIndex(int index) 
	{
		return agentList.get(index).id;	
	}
	
	public static int getRoleIdByIndex(int index) 
	{
		return agentList.get(index).role_id;	
	}
	
	public synchronized static boolean isAgentHere(PositionSq position) 
	{	
		for(int i=0;i<agentList.size();i++)
		{
			if(agentList.get(i).position_agent.equalTo(position))
			{
				return true;
			}
		}  
		
		return false;
	}
	
	
}
